//
//  XHPlayerCell.m
//  testApp
//
//  Created by ColdMountain on 2016/12/6.
//  Copyright © 2016年 ColdMountain. All rights reserved.
//

#import "XHPlayerCell.h"

@implementation XHPlayerCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)drawRect:(CGRect)rect
{
    CGContextRef ctx = UIGraphicsGetCurrentContext();
    //(1)画一张图片
    [self drawAPictureWithRect:rect andCurrentContect:ctx];
    CGContextSaveGState(ctx);
    CGContextRestoreGState(ctx);
}
- (void)drawAPictureWithRect:(CGRect)rect andCurrentContect:(CGContextRef)ctx
{
//    UIImage *img = [UIImage imageNamed:@"sucai"];
    CGFloat btnY=10;
    CGFloat btnX=10;
    CGFloat rowHeight=0;
    for (int i=0; i<9; i++) {
        UIImage *button = [UIImage imageNamed:@"sucai"];
        if (btnX+(SCREEN_WIDTH-30)/3+5>SCREEN_WIDTH) {
            btnY=btnY+5+(SCREEN_WIDTH-30)/3;
            btnX=10;
        }
         CGRect countRect = CGRectMake(btnX, btnY, (SCREEN_WIDTH-30)/3, (SCREEN_WIDTH-30)/3);
//        button.frame=CGRectMake(btnX, btnY,50, 50);
        btnX=btnX+5+(SCREEN_WIDTH-30)/3;
        rowHeight=btnY+(SCREEN_WIDTH-30)/3+10;
//        button.hidden=YES;
       [button drawInRect:countRect];
    }
//    [img drawInRect:countRect];
}

- (CGFloat)getImageSizeHeight
{
    CGFloat btnY=10;
    CGFloat btnX=10;
    CGFloat rowHeight=0;
    for (int i=0; i<9; i++) {
        UIButton *button=[self createMyImageView];
//        if (array.count==4) {
//            if (btnX+FrameW(button)+5>SCREEN_CONTENT_WIDTH-(SCREEN_WIDTH-30)/3) {
//                btnY=btnY+5+FrameH(button);
//                btnX=10;
//            }
//            button.frame=Frame(btnX, btnY, FrameW(button), FrameH(button));
//            btnX=btnX+5+FrameW(button);
//            rowHeight=btnY+(SCREEN_WIDTH-30)/3+10;
//        }else{
            if (btnX+FrameW(button)+5>SCREEN_CONTENT_WIDTH) {
                btnY=btnY+5+FrameH(button);
                btnX=10;
            }
            button.frame=Frame(btnX, btnY, FrameW(button), FrameH(button));
            btnX=btnX+5+FrameW(button);
            rowHeight=btnY+(SCREEN_WIDTH-30)/3+10;
//        }
    }
    return rowHeight;
}

- (UIButton*)createMyImageView
{
    CGFloat width=(SCREEN_WIDTH-30)/3;
    CGFloat height=width;
    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
    
    button.frame=CGRectMake(0, 0, width, height);
    
    return button;
}

- (IBAction)runAction:(id)sender
{
    [_delegate runAction:sender];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
